//
//  HDCFTradeHisCell.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/11/2.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFTradeHisCell.h"

@interface HDCFTradeHisCell ()
@property (weak, nonatomic) IBOutlet UILabel *fundName;
@property (weak, nonatomic) IBOutlet UILabel *buyMoney;
@property (weak, nonatomic) IBOutlet UILabel *tradeDay;
@property (weak, nonatomic) IBOutlet UILabel *payType;
@property (weak, nonatomic) IBOutlet UILabel *redLabe;

@property (nonatomic, strong) NSDictionary *typeDict;
@property (nonatomic, strong) NSDictionary *payTypeDict;
@end

@implementation HDCFTradeHisCell

- (void)setDataDictTwo:(NSDictionary *)dataDictTwo{
    _dataDictTwo = dataDictTwo;
    
    NSString *transactionType = dataDictTwo[@"transactionType"];
    
    if ([dataDictTwo[@"transactionType"] isKindOfClass:[NSNull class]]) {
        _redLabe.text = @"--";
    }else{
        _redLabe.text = self.typeDict[transactionType];
    }
    if ([dataDictTwo[@"portfolioName"] isKindOfClass:[NSNull class]]) {
        _fundName.text = @"--";
        _fundName.hidden = YES;
    }else{
        _fundName.hidden = NO;
        _fundName.text = dataDictTwo[@"portfolioName"];
    }
    
    if ([dataDictTwo[@"transactionAmount"] isKindOfClass:[NSNull class]]) {
        _buyMoney.text = @"订单未确认";
    }else{
        NSNumber *money = dataDictTwo[@"transactionAmount"];
        _buyMoney.text = [NSString stringWithFormat:@"%.2f", money.doubleValue];
    }
    
    if ([dataDictTwo[@"transactionDate"] isKindOfClass:[NSNull class]]) {
        _tradeDay.text = @"订单尚未下单成功";
    }else{
        NSNumber *navDate = dataDictTwo[@"transactionDate"];
        NSDateFormatter *stampFormatter = [[NSDateFormatter alloc] init];
        [stampFormatter setDateFormat:@"YYYY-MM-dd"];
        NSDate *stampDate2 = [NSDate dateWithTimeIntervalSince1970:[navDate doubleValue] / 1000];
        NSString *dateString = [stampFormatter stringFromDate:stampDate2];
        if ([dateString isEqualToString:@"1950-01-01"]) {
            _tradeDay.text = @"订单尚未下单成功";
        }else{
            _tradeDay.text = dateString;
        }
        
    }
    
    NSString *transactionStatus = dataDictTwo[@"transactionStatus"];
    if ([dataDictTwo[@"transactionStatus"] isKindOfClass:[NSNull class]]) {
        _payType.text = @"--";
    }else{
        _payType.text = self.payTypeDict[transactionStatus];
    }
}

- (NSDictionary *)typeDict{
    if (!_typeDict) {
        self.typeDict = @{@"buy":@"申购",
                          @"ipo":@"认购",
                          @"sell":@"赎回",
                          @"rsp":@"定投",
                          @"dividend":@"红利再投",
                          @"intra.swtich":@"同公司转换",
                          @"inter.switch":@"跨公司转换",
                          @"rapid.sell":@"快速取现",
                          @"sell.force":@"强制赎回",
                          @"units.increment":@"份额强增",
                          @"units.decrement":@"份额强减"
                          };
    }
    return _typeDict;
}

- (NSDictionary *)payTypeDict{
    if (!_payTypeDict) {
        self.payTypeDict = @{@"failure":@"支付失败",
                          @"received":@"下单成功",
                          @"priced":@"确认成功",
                          @"completed":@"交易成功",
                          @"ipo.processing":@"认购确认成功",
                          @"pending.payment":@"等待付款",
                          @"canceling":@"撤单中",
                          @"canceled":@"已撤单",
                          @"pending.void":@"等待退款",
                          @"void":@"交易失败"
                          };
    }
    return _payTypeDict;
}

- (void)setDataDict:(NSDictionary *)dataDict{
    _dataDict = dataDict;
    
    NSString *transactionType = dataDict[@"transactionType"];
    
    if ([dataDict[@"transactionType"] isKindOfClass:[NSNull class]]) {
        _redLabe.text = @"--";
    }else{
        _redLabe.text = self.typeDict[transactionType];
    }
    
    if ([dataDict[@"fundName"] isKindOfClass:[NSNull class]]) {
        _fundName.text = @"--";
    }else{
        _fundName.text = dataDict[@"fundName"];
    }
    
    if ([dataDict[@"transactionAmount"] isKindOfClass:[NSNull class]]) {
        _buyMoney.text = @"订单未确认";
    }else{
        NSNumber *money = dataDict[@"transactionAmount"];
        _buyMoney.text = [NSString stringWithFormat:@"%.2f", money.doubleValue];
    }
    
    if ([dataDict[@"transactionDate"] isKindOfClass:[NSNull class]]) {
        _tradeDay.text = @"订单尚未下单成功";
    }else{
        NSNumber *navDate = dataDict[@"transactionDate"];
        NSDateFormatter *stampFormatter = [[NSDateFormatter alloc] init];
        [stampFormatter setDateFormat:@"YYYY-MM-dd"];
        NSDate *stampDate2 = [NSDate dateWithTimeIntervalSince1970:[navDate doubleValue] / 1000];
        NSString *dateString = [stampFormatter stringFromDate:stampDate2];
        _tradeDay.text = dateString;
    }
    
    NSString *transactionStatus = dataDict[@"transactionStatus"];
    if ([dataDict[@"transactionStatus"] isKindOfClass:[NSNull class]]) {
        _payType.text = @"--";
    }else{
        _payType.text = self.payTypeDict[transactionStatus];
    }
    
}

+ (instancetype)HDCFTradeHisCell{
    return [[NSBundle mainBundle] loadNibNamed:@"HDCFTradeHisCell" owner:nil options:nil].firstObject;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    self.redLabe.layer.cornerRadius = 3.0;
    self.redLabe.clipsToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
